#!/bin/bash

echo '# Set PATH, MANPATH, etc., for Homebrew.' >>~/.zprofile
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"' >>~/.zprofile
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"' >>~/.zprofile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"' >>~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"' >>~/.zprofile

if [[ "$(uname -s)" == "Darwin" ]]; then
	if [[ "$(uname -m)" == "arm64" ]]; then
		# On ARM macOS, this script installs to /opt/homebrew only
		eval "$(/opt/homebrew/bin/brew shellenv)"
		echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >>~/.zprofile
	else
		eval "$(/usr/local/bin/brew shellenv)"
	fi
fi

if [[ "$(uname -s)" == "Linux" ]]; then
	eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
	echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >>~/.zprofile
fi
source ~/.zprofile
